package com.leetcode.algorithm.y22.m08.w4;

/**
 * 2024. 考试的最大困扰度
 * 
 * https://leetcode.cn/problems/maximize-the-confusion-of-an-exam/
 * 
 * @author jie.deng
 *
 */
class Question2024Solution01 {

	public int maxConsecutiveAnswers(String answerKey, int k) {
		int len = answerKey.length();
		int cntT = 0;
		int cntF = 0;
		int left = 0;
		int max = 0;
		for (int right = 0; right < len; right++) {
			if (answerKey.charAt(right) == 'T') {
				cntT++;
			} else {
				cntF++;
			}
			while (cntT > k && cntF > k) {
				if (answerKey.charAt(left) == 'T') {
					cntT--;
				} else {
					cntF--;
				}
				left++;
			}
			max = Math.max(max, right - left + 1);
		}

		return max;
	}

}